/**
 * 此游戏所有的图片资源管理和加载类
 * @author zhouzhanglin
 */
ResManager = function()
{
	EventDispatcher.call( this );

	this._total = 0 ; 
	this._loaded = 0 ;
	this._resArray ;
};
ResManager.prototype = new EventDispatcher(); //继承自EventDispatcher
ResManager.prototype.constructor = ResManager ;

/**
 * 获取实例
 * @returns
 */
ResManager.getInstance = function()
{
	if(!ResManager._instance){
		ResManager._instance=new ResManager();
	}
	return ResManager._instance ;
};

/**
 * 通过名称来获取图片数据BitmapData
 * @return bitmapData
 */
ResManager.prototype.getBmdByName = function( name){
	return ResPool.getInstance().getResVOByName(name).content.getBitmapData() ;
};

/**
 * 开始下载
 */
ResManager.prototype.startLoad = function()
{
	var resPool = ResPool.getInstance() ;
	this._resArray =[
		new ResVO("back", "imgs/back.jpg"),
		new ResVO("background-tree", "imgs/background-tree.png"),
		new ResVO("candy-right-long", "imgs/candy-right-long.png"),
		new ResVO("candy-right-middle", "imgs/candy-right-middle.png"),
		new ResVO("candy-right-short", "imgs/candy-right-short.png"),
		new ResVO("character", "imgs/character.png"),
		new ResVO("close-pop-up-bt", "imgs/close-pop-up-bt.png"),
		new ResVO("deer-large", "imgs/deer-large.png"),
		new ResVO("gift-left", "imgs/gift-left.png"),
		new ResVO("hint-back1", "imgs/hint-back1.png"),
		new ResVO("logo-splash", "imgs/logo-splash.png"),
		new ResVO("next_level", "imgs/next_level.jpg"),
		new ResVO("play-bt-splash", "imgs/play-bt-splash.png"),
		new ResVO("pop-up", "imgs/pop-up.png"),
		new ResVO("score-control", "imgs/score-control.png"),
		new ResVO("splash-bg", "imgs/splash-bg.jpg")
	];
	
	var _self =this ;
	function resQueueLoadedHandler(e){
		resPool.removeEventListener(ResLoadedEvent.RES_QUEUE_LOADED , resQueueLoadedHandler);
		resPool.removeEventListener(ResProgressEvent.RES_LOAD_PROGRESS , resLoadingHandler);
		_self.dispatchEvent( new Event( Event.COMPLETE));
		_self._resArray = null ;
	}
	function resLoadingHandler(e){
		var evt = new ProgressEvent(ProgressEvent.PROGRESS , ( e.getProgress()*100)>>0 , 100 );
		_self.dispatchEvent( evt );
	}
	resPool.addEventListener(ResLoadedEvent.RES_QUEUE_LOADED , resQueueLoadedHandler);
	resPool.addEventListener(ResProgressEvent.RES_LOAD_PROGRESS , resLoadingHandler);
	resPool.queueLoad(this._resArray,4);
};